package com.example.no1admin.controller;

import com.example.no1admin.pojo.dto.photographer.PhotographerAddNewDTO;
import com.example.no1admin.pojo.dto.photographer.PhotographerEditDTO;
import com.example.no1admin.pojo.vo.photographer.PhotographerListItemVO;
import com.example.no1admin.service.IPhotographerService;
import com.example.no1admin.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "摄影师管理模块")
@RequestMapping("/photographers")
@Slf4j
@RestController
public class PhotographerController {
    @Autowired
    IPhotographerService photographerService;

    @ApiOperation("添加摄影师")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@RequestBody PhotographerAddNewDTO photographerAddNewDTO){
        log.debug("接受到的请求参数:{}",photographerAddNewDTO);
        photographerService.addNew(photographerAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除摄影师")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete-by-id")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("接收到删除摄影师的请求");
        photographerService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改摄影师信息")
    @PreAuthorize("hasAuthority('ROLE_admin')")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update")
    public JsonResult updateById(@RequestBody PhotographerEditDTO photographerEditDTO){
        log.debug("接收到修改摄影师的请求");
        photographerService.updateById(photographerEditDTO);
        return JsonResult.ok();
    }

    @ApiOperation("摄影师列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult list(){
        log.debug("接收到查询摄影师列表的请求");
        List<PhotographerListItemVO> photographers = photographerService.list();
        return JsonResult.ok(photographers);
    }
}
